//
//  WFVisitorTVC.swift
//  WangFangWeiBo
//
//  Created by 王方 on 16/7/9.
//  Copyright © 2016年 wf. All rights reserved.
//

import UIKit

class WFVisitorTVC: UITableViewController {
    
    
    //标记一个登陆的bool
    var isLogin:Bool = WFUserAccountViewModel.sharedUserAccount.isLogin
    
    //访客视图
    var visitorView:WFVisitorView?
    
    //在很早的方法中进行初始化左右两边的按钮
    override func loadView() {
        if isLogin {
        //如果已经登陆
            super.loadView()
        }else {
        //如果没有登陆
            visitorView = WFVisitorView()
            //由于有循环引用,必须用weak解决
            visitorView?.loginOrRegisterClosure = {[weak self] in
                print(self)
            self!.jumpToOAuthLogin()
            }
            view = visitorView
            setUpNavUI()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

       
    }
    
    // MARK:  - 初始化左右两边的注册和登陆按钮
    func setUpNavUI(){
        
    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册",target: self,action: "registerBtnClick")
    navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆",target: self,action: "loginBtnClick")
        
    }
    
   @objc private func registerBtnClick(){
    print("注册按钮被点击了")
        jumpToOAuthLogin()
    }
    @objc private func loginBtnClick(){
    print("登陆按钮被点击了")
        jumpToOAuthLogin()
    }
    
    // MARK:  - 跳转到授权登录页面(modal方式)
    private func jumpToOAuthLogin(){
        let oauthVC = WFOAuthVC()
        let nav = UINavigationController(rootViewController: oauthVC)
        presentViewController(nav, animated: true, completion: nil)
        
    }
    
}
